﻿using ERPSystem.Common.Domains.ReturnNotice;
using ERPSystem.Common.DTO;
using ERPSystem.Enum.CommonErrorCodes;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using Newtonsoft.Json;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using SalesManagementCommon.API.SalesManagementCommons.ReturnNotices;
using SalesManagementCommon.API.SalesManagementCommons.Shippingnotess;
using SqlSugar;
using static ERPSystem.Common.DTO.ReturnDTO;

namespace SalesManagementCommon.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ReturnNoticesesController : ControllerBase
    {
        private readonly IMediator mediator;

        public ReturnNoticesesController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 退货通知单列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<PageResultDto<ReturnNoticesDTO>>> GetreturnNotice([FromQuery]ReturnNoticeQueryCommon request, CancellationToken cancellationToken)
        {
            var result = await mediator.Send(request, cancellationToken);
            return result;
        }

        /// <summary>
        /// 退货通知单导出
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> ReturnNoticeExport([FromQuery]ReturnNoticesExcelCommand request)
        {
           var result = await mediator.Send(request);
            return File(result.FileBytes, result.MimeType, result.FileName);
        }

        /// <summary>
        /// 退货通知单回填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<ReturnDTO>> GetFTreturnNotice([FromQuery]ReturnNoticeBackFillCommon request, CancellationToken cancellationToken)
        {
            var result = await mediator.Send(request, cancellationToken);
            return result;
        }

    }
}
